package edu.buaa.energy.transaction;


import edu.buaa.common.transaction.AbstractTransaction;
import edu.buaa.utils.Helper;
import edu.buaa.utils.Pair;

import java.util.List;
import java.util.stream.Collectors;

public class SnapshotAggrMaxTx extends AbstractTransaction {
    private int t0;
    private int t1;
    private String p;

    public SnapshotAggrMaxTx() {
        this.setTxType(TxType.tx_query_snapshot_aggr_max);
    }

    public int getT0() {
        return t0;
    }

    public int getT1() {
        return t1;
    }

    public String getP() {
        return p;
    }

    public void setT0(int t0) {
        this.t0 = t0;
    }

    public void setT1(int t1) {
        this.t1 = t1;
    }

    public void setP(String p) {
        this.p = p;
    }

    public static class Result extends AbstractTransaction.Result {
        List<Pair<Integer, Float>> propMaxValue;

        public List<Pair<Integer, Float>> getPropMaxValue() {
            return propMaxValue;
        }

        public void setPropMaxValue(List<Pair<Integer, Float>> propMaxValue) {
            this.propMaxValue = propMaxValue;
        }
    }

    @Override
    public boolean validateResult(AbstractTransaction.Result result) {
        return Helper.validateResult(conv(((Result) this.getResult()).getPropMaxValue()), conv(((Result) result).getPropMaxValue()));
    }

    private List<Pair<Integer, Integer>> conv(List<Pair<Integer, Float>> from){
        return from.stream().map(t2 -> Pair.of(t2.getKey(), t2.getValue().intValue())).collect(Collectors.toList());
    }
}
